﻿-- Author      : Kurapica
-- Create Date : 7/16/2008 14:28
     
-- ScrollingMessageFrame
do
	-- Check Version
	local version = 1
	if not IGAS:RegisterFile("IGAS.GUI.Widget.ScrollingMessageFrame", version) then
		return
	end

    local getmetatable = getmetatable
    local pairs = pairs
    local ipairs = ipairs
    local type = type
    local error = error
    local CreateFrame = CreateFrame
    
	local _WidgetName = "ScrollingMessageFrame"
    local _Base = "FontFrame"

	local _GUI = IGAS.GUI
	local _Widget = IGAS.GUI.Widget
    local _BaseFunc = IGAS.GUI.Base.Func
	local _PropertyType = IGAS.GUI.Base.PropertyType   
	
	-- ScriptType
	local _ScriptType = {
	}
    
	-- FuncProxy
	local _FuncProxy = {        
    }
    
	-- Property
	local _Property = {
        -- Fading
        ["Fading"] = {
			["Set"] = function(self, state)
				self.__UI:SetFading(state)
			end,
			
			["Get"] = function(self)
				return (self.__UI:GetFading() and true) or false
			end,
			
			["Type"] = _PropertyType.Boolean,
		},
  
        -- TimeVisible
        ["TimeVisible"] = {
			["Set"] = function(self, seconds)
				self.__UI:SetTimeVisible(seconds)
			end,
			
			["Get"] = function(self)
				return self.__UI:GetTimeVisible()
			end,
			
			["Type"] = _PropertyType.Number,
		},
	
        -- FadeDuration
        ["FadeDuration"] = {
			["Set"] = function(self, seconds)
				self.__UI:SetFadeDuration(seconds)
			end,
			
			["Get"] = function(self)
				return self.__UI:GetFadeDuration()
			end,
			
			["Type"] = _PropertyType.Number,
		},
	 
        -- InsertMode
        ["InsertMode"] = {
			["Set"] = function(self, mode)
				self.__UI:SetInsertMode(mode)
			end,
			
			["Get"] = function(self)
				return self.__UI:GetInsertMode()
			end,
			
			["Type"] = _PropertyType.InsertMode,
		},	
          
        -- MaxLines
        ["MaxLines"] = {
			["Set"] = function(self, lines)
				self.__UI:SetMaxLines(lines)
			end,
			
			["Get"] = function(self)
				return self.__UI:GetMaxLines()
			end,
			
			["Type"] = _PropertyType.Number,
		},     
   }
	
    -- New      
    local _New = function(_parent,inheritFrame)
        -- New Frame
		local frame = CreateFrame(_WidgetName,nil,_BaseFunc.GetUI(_parent),inheritFrame)
		
        return frame
    end
	
    local _WidgetInfo = {
        ["WidgetName"] = _WidgetName,
        ["Base"] = _Base,
        ["FuncProxy"] = _FuncProxy,
        ["Property"] = _Property,
        ["ScriptType"] = _ScriptType,
        ["New"] = _New,
    }
    
    _Widget[_WidgetName] = _GUI.NewWidget(_WidgetInfo)
    
	------------------------------------------------------
	--------------- Scan new function --------------------
    ------------------------------------------------------
	local _frame = CreateFrame(_WidgetName,nil,UIParent)
	
	local _oriMeta = getmetatable(_frame)
	_oriMeta = _oriMeta.__index
    
    local _func = _Widget[_WidgetName]["FuncProxy"]
	-- Other Function
	for _f in pairs(_oriMeta) do
		if not _func[_f] and type(_oriMeta[_f]) == "function" then
			_func[_f] = function(self, ...)
                return _BaseFunc.GetVals(self.__UI[_f](self.__UI, _BaseFunc.GetArgs(...)))
			end
		end
	end
	
	-- Clear
	_oriMeta = nil
    _frame:Hide()
	_frame = nil
end